﻿angular.module('ishaCrmApp')

    .factory('memberService', ['$q','$rootScope', '$cookieStore', 'googleAuthSvc', function ($q, $rootScope, $cookieStore, googleAuthSvc) {
        
        var memberSvc = {};
        var deferred = $q.defer();
        var promise = deferred.promise;

        memberSvc.getMember = function(id){
            gapi.client.member.memberApi.get({ client: app.CRM_CLIENT, member_id: id }).execute(function (resp) {
                switch (resp.statusCode) {
                    case 'SUCCESS':
                        {
                            return (deferred.resolve(resp.object));
                        }
                    case 'ERROR_LOGIN_REQUIRED':
                        {
                            return (deferred.reject({ 'errorinfo': resp.statusCode + (resp.userFriendlyMessage ? ': ' + resp.userFriendlyMessage : '')}));
                        }
                }
            });
            return promise;
        };

        return memberSvc;
    }]);